import logging

import allure
import requests

from common.config import getconf, caryylogin, Excel, data_path


class DataStatistics():
    def __init__(self):
        self.dataStatistics = logging.getLogger("dataStatistics")

    """ 
        测试门店：
               [ { "id": 25962, "simpleName": "乐乐茶" }, { "id": 26167, "simpleName": "测试地上停车场" }, { "id": 26376, "simpleName": "麦当劳" }, { "id": 26980, "simpleName": "乐高" }, { "id": 30240, "simpleName": "kfc" } ]
    """

    @allure.step('创建测试数据')
    def create_spu_data_list(self, env,job_at):
        """门店数据列表"""
        data = Excel(data_path + 'data_dashboard_spu.xlsx')
        val_sql=""
        for dd in data:
            val_sql+= "('"+job_at+"','"+job_at+"',0,"+str(int(dd[0]))+","+str(int(dd[1]))+","+str(int(dd[2]))+","+str(int(dd[3]))+",'"+dd[4]+"','"+dd[5]\
                  +"','"+dd[6]+"','"+dd[7]+"','"+dd[8]+"',"+str(int(dd[9]))+","+str(int(dd[10]))+",1),"
        val_sql=val_sql[:-1]+";"
        return val_sql

    @allure.step('创建测试数据')
    def create_sku_data_list(self, env, job_at):
        """门店数据列表"""
        data = Excel(data_path + 'data_dashboard_sku.xlsx')
        val_sql = ""
        for dd in data:
            val_sql += "('" + job_at + "','" + job_at + "',0," + str(int(dd[0])) + "," + str(int(dd[1])) + "," + str(int(dd[2])) + ","
            + str(int(dd[3])) + "," + str(int(dd[4])) + ",'" + dd[5] + "','" + dd[6] + "'," + str(int(dd[7])) + ",'" + dd[8] + "','"
            + dd[9] + "','" +"','"+ dd[11] + "'," + str(int(dd[12])) + "," + str(int(dd[13])) + ",1),"

            break
        val_sql = val_sql[:-1] + ";"
        return val_sql

    @allure.step('门店数据列表')
    def shop_data_list(self, env,branchId=25961,shopIds=[],startDate="2022-08-01",endDate="2022-08-07",size=10,current=1):
        """门店数据列表"""
        zhongtai_url = getconf(env, "zhongtai_url")
        token = caryylogin(env)
        headers = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data = {"branchId":branchId,"shopIds":shopIds,"startDate":startDate,"endDate":endDate,"size":size,"current":current}
        url = zhongtai_url + "platform-data-dashboard-server/v1/listDayDataStatistics/shop"
        self.dataStatistics.info("查看商品列表的请求参数：{}".format(data))
        return requests.post(json=data, url=url, headers=headers)

if __name__ == '__main__':
    dd= DataStatistics()
    print(dd.create_sku_data_list(1,"2023-05-05"))
    # val_sql = "1111,"
    # val_sql = val_sql[:-1]+";"
    # print(val_sql)
    # from datetime import date, timedelta
    #
    # yesterday = (date.today() + timedelta(days=-1)).strftime("%Y-%m-%d")
    # print(yesterday)